home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / CENVIW2.ZIP / CMMTUTOR.DOC < prev    next >
Text File  |  1993-09-13  |  49KB  |  1,125 lines

  1.                     CEnvi Shareware Manual, Chapter 2:
  2.                            Cmm Language Tutorial
  3.  
  4.  
  5.                      CEnvi unregistered version 1.003
  6.                              13 September 1993
  7.  
  8.                        CEnvi Shareware User's Manual
  9.  
  10.           Copyright 1993, Nombas, All Rights Reserved.
  11.           Published by Nombas, P.O. Box 875, Medford, MA 02155 USA
  12.           (617)391-6595
  13.  
  14.           Thank you for trying this shareware version of CEnvi from Nombas.
  15.  
  16. 2.  The Cmm Language: Tutorial for Non-C Programmers
  17.  
  18.           The information in this chapter is geared toward those who are
  19.           not familiar with the C programming language.  C programmers
  20.           should jump ahead to the next chapter: Cmm versus C.  This
  21.           section is an introduction to and description of the Cmm
  22.           programming language.
  23.  
  24.           If you can write a batch, script, or macro file, or if you can
  25.           remember what "y = x + 1" means from your algebra class, then
  26.           you're ready to take on Cmm.  Really.  Cmm contains only
  27.           variables, mathematics symbols (remember algebra), and these few
  28.           statements: IF, ELSE, DO, WHILE, FOR, SWITCH, CASE, BREAK,
  29.           DEFAULT, CONTINUE, GOTO, and RETURN.
  30.  
  31.           This section is an abbreviation of the Cmm Language Tutorial
  32.           chapter in the CEnvi registered manual.  The CEnvi registered
  33.           manual goes into much more depth, has many more examples, and
  34.           follows a step-by-step tutorial to create a simple text editor
  35.           with CEnvi.
  36.  
  37. 2.1.  Your first Cmm program
  38.  
  39.           Before going into a description of Cmm, let's first make sure
  40.           that CEnvi is working properly.  With a text editor (e.g., EDIT
  41.           for DOS, E for OS/2, or NOTEPAD for Windows) create the file
  42.           HELLO.CMM and enter this text:
  43.  
  44.               // Hello.cmm: My first Cmm program
  45.               Count = 1; /* Count is how many Cmm programs I've written */
  46.               printf("Hello world. This is my %dst Cmm program.\n",Count);
  47.               printf("Press any key to quit...");
  48.               getch();
  49.  
  50.           You have now written a Cmm program named "HELLO.CMM".  Don't be
  51.           concerned if you do not yet understand the HELLO.CMM program; it
  52.           should become clear as Cmm is defined.  Now execute this program
  53.           (for DOS or OS/2 you would enter "CENVI HELLO.CMM" and for
  54.           Windows you need may use the File Manager and double-click on the
  55.           file name).  You should get this output:
  56.  
  57.               Hello world. This is my 1st Cmm program.
  58.               Press any key to quit...
  59.  
  60.  
  61.           If this program will execute, then you are ready to go on to
  62.           learn about Cmm.  If it did not execute then consult the CEnvi
  63.           installation section in the first chapter of this shareware
  64.           manual.
  65.  
  66. 2.2.  Cmm comments
  67.  
  68.           Comments are used in Cmm code to explain what the code does, but
  69.           the comment itself does nothing.  Comments are very useful in
  70.           programming.  A comment takes nothing away from the execution of
  71.           a program, but adds immeasurably to the readability of the source
  72.           code.
  73.  
  74.           In Cmm, any text on a line following two slash characters (//) is
  75.           considered a comment and so is ignored by the Cmm interpreter.
  76.           Likewise, anything between a slash-asterisk (/*) and an
  77.           asterisk-slash (*/) is a comment (this type of comment may extend
  78.           over many lines).  In the HELLO.CMM program there is a "//"
  79.           comment on the first line and a "/* blah blah */" comment on the
  80.           second line.
  81.  
  82. 2.3.  Cmm primary data types
  83.  
  84.           There are three principal data types in Cmm:
  85.             *Byte: A character (e.g., 'D') or a whole number between 0 and
  86.               255, inclusive
  87.             *Integer: A whole number value; this is the most common numeric
  88.               data type (examples: 0, -1000, 567, 4335600)
  89.             *Float: floating point numbers; any number containing a decimal
  90.               point (examples: 0.567, 3.14159, -5.456e-12)
  91.  
  92.           Cmm determines the data type of a number by how it is used; for
  93.           example, in the HELLO.CMM program the "1" in the second line is
  94.           an integer because that is the default type for numbers without a
  95.           decimal point.
  96.  
  97. 2.3.1   Escape Sequences for Characters
  98.  
  99.           Certain characters are represented with a multi-character
  100.           sequence beginning with a backslash (\).  These are called escape
  101.           sequences, and have the following meanings:
  102.               \a      Audible bell
  103.               \b      Backspace
  104.               \f      Formfeed
  105.               \n      Newline
  106.               \r      Carriage return
  107.               \t      Tab
  108.               \v      Vertical tab
  109.               \'      Single quote
  110.               \"      Double quote
  111.               \\      Backslash character
  112.               \###    Octal number  // ex: '\033' is escape character
  113.                                     // ex: \0 is null character
  114.               \x##    Hex number    // '\x1B' is escape character
  115.  
  116. 2.4.  Cmm Variables
  117.  
  118.           A Cmm variable is a symbol that may be assigned data.  The
  119.           assignment of data is usually performed by the equal sign (=), as
  120.           in the line "Count = 1" in HELLO.CMM.  After variables have been
  121.           assigned, they can be treated as their data type.  So, after
  122.           these statements:
  123.               Count = 1               // assign count as the integer 1
  124.               Count = Count + 2       // same as: Count = 1 + 2
  125.           Count would now have the value 3.
  126.  
  127. 2.5.  Cmm Expressions, Statements, and Blocks
  128.  
  129.           A Cmm "expression" or "statement" is any sequence of code that
  130.           perform a computation or take an action (e.g., "Count=1",
  131.           "(2+4)*3").  Cmm code is executed one statement at a time in the
  132.           order it is read.  A Cmm program is a series of statements
  133.           executed sequentially, one at a time.  Each line of HELLO.CMM,
  134.           for example, follows the previous line as it is written and as it
  135.           is executed.
  136.  
  137.           A statement usually ends in a semicolon (;) (this is required in
  138.           C, and still a good idea in Cmm to improve readability).  Each
  139.           program statement is usually written on a separate line to make
  140.           the code easy to read.
  141.  
  142.           Expressions may be grouped to effect the sequence of processing;
  143.           expressions inside parentheses are processed first.  Notice that:
  144.               4 * 7 - 5 * 3       // 28 - 14 = 13
  145.           has the same meaning, do to algebraic operator precedence, as:
  146.               (4 * 7) - (5 * 3)   // 28 - 15 = 13
  147.           but has a different meaning than:
  148.               4 * (7 - 5) * 3     // 4 * 2 * 3 = 8 * 3 = 24
  149.           which is still different from:
  150.               4 * (7 - (5 * 3))   // 4 * (7 - 15) = 4 * -8 = -32
  151.  
  152.           A "block" is a group of statements enclosed in curly braces ({})
  153.           to show that they are all a group and so are treated as one
  154.           statement.  For example, HELLO.CMM may be rewritten as:
  155.               // Hello.cmm: My first Cmm program
  156.               Count = 1; /* Count is how many Cmm programs I've written */
  157.               printf("Hello world. This is my %dst Cmm program.\n",Count);
  158.               {
  159.                 // this block tells the user we're done, and quits
  160.                 printf("Press any key to quit...");
  161.                 getch();
  162.               }
  163.           The indentation of statements is not necessary, but is useful for
  164.           readability.
  165.  
  166. 2.6.  Cmm Mathematical Operators
  167.  
  168.           Cmm code usually contains some mathematical operations, such as
  169.           adding numbers together, multiplying, dividing, etc.  These are
  170.           written in a natural way, such as "2 + 3" when you want to add
  171.           two and three.  The next few subsections define the recognized
  172.           operators within